package cn.demo.admin.controller.sys;

import cn.demo.common.annotation.Log;
import cn.demo.common.core.controller.BaseController;
import cn.demo.common.core.domain.R;
import cn.demo.common.core.page.PageQuery;
import cn.demo.common.core.page.PageR;
import cn.demo.common.enums.BusinessType;
import cn.demo.sys.domain.SysNotice;
import cn.demo.sys.service.ISysNoticeService;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告 信息操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/sys/notice")
public class SysNoticeController extends BaseController {
    @Resource
    private ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('sys:notice:list')")
    @GetMapping("/list")
    public PageR<SysNotice> list(SysNotice notice, PageQuery pageQuery) {
        Page<SysNotice> list = noticeService.selectNoticePage(notice, pageQuery);
        return PageR.ok(list);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('sys:notice:query')")
    @GetMapping(value = "/{noticeId}")
    public R getInfo(@PathVariable String noticeId) {
        return R.ok(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('sys:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@Validated @RequestBody SysNotice notice) {
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('sys:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@Validated @RequestBody SysNotice notice) {
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('sys:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public R remove(@PathVariable List<String> noticeIds) {
        return toAjax(noticeService.deleteNoticeByIds(noticeIds));
    }
}
